<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue源码系列2.x</title>
</head>

<body>
    <div id="app">
        <h3 test="test" :name="t">Deep Data: </h3>
        <p v-bind:bindname="t">{{t2}}</p>
        <h3>Methods Operator: </h3>
        <p>data/methods: {{counter}}</p>
        <button @click="add">++</button>
        <button @click="decrea">--</button>
        <h3>v-model: </h3>
        <p>v-model: {{t}}</p>
        <input type="text" v-model="t">
        <h3>CheckBox：</h3>
        <span>checkbox current value：</span>
        <input type="checkbox" v-model="status">
        <button @click="changeBox">改变status</button>
        <h3>Select Options: </h3>
        <select v-model="selectValue">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
        </select>
        <span>选择的选项是{{selectValue}}</span>
        <h3>Array Operator:</h3>
        <p>数组：{{ arr }}</p>
        <button @click="changeArr">changeArr</button>
        <button @click="addArrElem">addArrElem</button>
        <h3>子组件：</h3>
        <comp></comp>
        <h3>Computed:</h3>
        <p>computed: {{ret}}</p>
    </div>
    <script type="module">
        import Vue from "./core/index.js"
        let app = new Vue({
            el: "#app",
            data() {
                return {
                    t: "绑定值",
                    arr: [1, 2, 3, 4],
                    t2: {
                        t3: "t3 text"
                    },
                    counter: 1,
                    d: 10,
                    status: true,
                    selectValue: 2
                }
            },
            components: {
                'comp': {
                    template:
                        `<div>
                        <p>{{count}}</p>
                        <p>{{doubleCount}}</p>
                        <p>{{doubleCount}}</p>
                        <button @click="childAdd">child++</button>
                        <button @click="childDec">child--</button>
                        </div>`,
                    data() {
                        return {
                            count: 0
                        }
                    },
                    computed: {
                        doubleCount() {
                            console.log("计算属性重新计算。。")
                            return this.count * 2
                        }
                    },
                    methods: {
                        childAdd() {
                            this.count++
                        },
                        childDec() {
                            this.count--
                        }
                    }
                }
            },
            methods: {
                add() {
                    this.counter = this.counter + 1
                },
                decrea() {
                    this.counter = this.counter - 1
                },
                changeBox() {
                    this.status = !this.status
                },
                changeArr() {
                    this.arr = [{ newP: 1 }]
                },
                addArrElem() {
                    this.arr.push(this.counter)
                }
            },
            computed: {
                ret() {
                    return this.counter + this.d
                }
            }
        });
        setTimeout(() => {
            console.log("=========================")
            app.t = "新修改的值"
            app.t2 = { newvalue: "新值" }
            console.log("=========================")
        }, 1000);
        setTimeout(() => {
            console.log("=========================")
            app.t2.newvalue = 'this is my new value...'
            app.arr = [{res : 1}]
            console.log("=========================")
        }, 2000);
        setTimeout(() => {
            console.log("=========================")
            app.arr.push(3)
            console.log("=========================")
        }, 3000);
    </script>
</body>

</html>